package vsm.vsm_server.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import vsm.vsm_server.pojo.CF.User_User_CF;
import vsm.vsm_server.pojo.CF.User_Video_CF;
import vsm.vsm_server.pojo.CF.Video_Video_CF;

import java.math.BigInteger;
import java.util.List;

@Mapper
public interface CFMapper{

    @Select("select * from user_video_cf where userId = #{userId} order by updateTime desc,interest desc limit #{count}")
    List<User_Video_CF> getUserInterest(BigInteger userId, int count);

    @Select("select * from user_user_cf where userId = #{userId} order by updateTime desc,interest desc limit #{count}")
    List<User_User_CF> getUserSim(BigInteger userId, int count);

    @Select("select * from video_video_cf where videoId = #{videoId} order by updateTime desc,interest desc limit #{count}")
    List<Video_Video_CF> getItemSim(BigInteger videoId, int count);

    @Insert("insert into user_video_cf(userId,toVideoId,interest,updateTime) values(#{userId},#{toVideoId},#{interest},#{updateTime})" +
            "ON DUPLICATE KEY UPDATE " +
            "interest = VALUES(interest),"+
            "updateTime = VALUES(updateTime)")
    void saveUserVideoCF(User_Video_CF userVideoCf);

    @Insert("insert into user_user_cf(userId,toUserId,interest,updateTime) values(#{userId},#{toUserId},#{interest},#{updateTime})" +
            "ON DUPLICATE KEY UPDATE " +
            "interest = VALUES(interest),"+
            "updateTime = VALUES(updateTime)")
    void saveUserUserCF(User_User_CF userUserCf);

    @Insert("insert into video_video_cf(videoId,toVideoId,interest,updateTime) values(#{videoId},#{toVideoId},#{interest},#{updateTime})" +
            "ON DUPLICATE KEY UPDATE " +
            "interest = VALUES(interest),"+
            "updateTime = VALUES(updateTime)")
    void saveVideoVideoCF(Video_Video_CF videoVideoCf);

}
